package com.mj.express.adapter;

import java.util.List;

import com.mj.express.R;
import com.mj.express.bean.ExpressCompany;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
 * 快递公司下拉列表
 * @author zhaominglei
 * @date 2015-3-16
 * 
 */
public class CompanySpinnerAdapter extends BaseAdapter {
	private List<ExpressCompany> expressCompanies;
	private Context context;
	
	public CompanySpinnerAdapter(Context context, List<ExpressCompany> expressCompanies) {
		super();
		this.context = context;
		this.expressCompanies = expressCompanies;
	}

	public List<ExpressCompany> getExpressCompanies() {
		return expressCompanies;
	}


	public void setExpressCompanies(List<ExpressCompany> expressCompanies) {
		this.expressCompanies = expressCompanies;
	}

	@Override
	public int getCount() {
		return expressCompanies.size();
	}

	@Override
	public Object getItem(int position) {
		return expressCompanies.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView expressCompanyText;
		if (convertView != null) {
			expressCompanyText = (TextView) convertView;
		} else {
			expressCompanyText = (TextView) View.inflate(context, R.layout.expresscompany_item, null);
		}
		expressCompanyText.setText(expressCompanies.get(position).getName());
		expressCompanyText.setTag(expressCompanies.get(position).getCode());
		return expressCompanyText;
	}
}
